package com.deimos.dataBase.utils;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.deimos.dataBase.TaskController;

/**
 * Servlet implementation class BuildDBServlet
 */
public class UtilsDBServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public UtilsDBServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter out = null;
		out = response.getWriter();
		TaskController taskController = new TaskController();

		String queryString = request.getQueryString();

		if (queryString != null
				&& queryString.toLowerCase().contains("createtables")) {
			taskController.createTables(true);
			//taskController.addTasks();
			out.println("Tables created\n");
			out.println("Sample data created\n");
		}
	
		if (queryString != null && queryString.toLowerCase().contains("purge")) {
			out.println(taskController.purge());
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
